/**
 * VideoBrowserServlet.java
 */
package com.example.myproject;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class VideoBrowserServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		VideoUploadDAO video = new VideoUploadDAO();
		List<VideoUploadDTO> list = video.list();
		HashMap<String, String> result = new HashMap<String, String>();
		StringBuffer resultHtml = new StringBuffer();
			
		/*
		 * it retrieves video file series
		 * to show group of video file 
		 */
		for(int i=0; i < list.size(); i++)
		{
			if(!"".equals(list.get(i).getSeries()) && list.get(i).getSeries() != null)
			{
				if(i==0)
				{
					resultHtml.append("<li>");
					resultHtml.append("<a href=videobrowser?fileType=video&sortType="+list.get(i).getSeries()+">");
					resultHtml.append(list.get(i).getSeries());
					resultHtml.append("</a></li>");
					result.put(list.get(i).getSeries(), list.get(i).getSeries());
				}
				else
				{
					if(!result.containsKey(list.get(i).getSeries()))
					{
						resultHtml.append("<li>");
						resultHtml.append("<a href=videobrowser?fileType=video&sortType="+list.get(i).getSeries()+">");
						resultHtml.append(list.get(i).getSeries());
						resultHtml.append("</a></li>");
						result.put(list.get(i).getSeries(), list.get(i).getSeries());
					}
				}
			}
			
		}
			
		//setting for showing front page
		req.setAttribute("videosort", resultHtml);
		
		RequestDispatcher view = req.getRequestDispatcher("index.jsp");
        view.forward(req, resp);

	}

}